<?php

namespace App;

use App\BaseModel;

class Topic extends BaseModel
{
    // 属于这个专题的所有文章   多对多
    public function posts() {
        return $this->belongsToMany(\App\Post::class, 'post_topics', 'topic_id', 'post_id');
    }

    // 专题文章数, 用于withCount
    public function postTopics() {
        return $this->hasMany(\App\PostTopic::class, 'topic_id');
    }
}
